import { Page } from '@/base/Page';
import { deleteMember, getMemberList, getMemberPointRanking, getMemberRanking } from '@/base/api/MemberApi';
import { Member } from '@/base/model/Member';
import { MemberSpecific2, MemberSpecific3 } from '@/base/model/MemberSpecific';
import { isEmpty } from '@/base/util/Strings';
import {getAgentList} from '@/base/api/AgentApi';
import {Agent} from '@/base/model/Agent';
import axios from 'axios';
import Cookies from 'js-cookie';

class Form {
  nickname = '';
  phone = '';
  point = 0;
  createBegin = '';
  createEnd = '';
  date = [];
  companyId = [];
  sortProperties = 'id';
  sortDirection = 'DESC';
  modelName = '';
  province = '';
  city = '';
  deviceSn = '';
  birthdayDate = undefined;
  
}
class Form3 {
  nickname = '';
  phone = '';
  point = 0;
  createBegin = '';
  createEnd = '';
  date = [];
  companyId = [];
  sortProperties = 'integral';
  sortDirection = 'DESC';
  modelName = '';
  province = '';
  city = '';
  deviceSn = '';
  birthdayDate = undefined;
}


export class ListBloc {
  form = new Form();
  form3 = new Form3();

  // paged: Page<Member> = new Page<Member>([], 0, 1, 15, 0, []);
  paged: Page<MemberSpecific2> = new Page<MemberSpecific2>([], 0, 1, 15, 0, []);
  paged3: Page<MemberSpecific3> = new Page<MemberSpecific3>([], 0, 1, 15, 0, []);
  angent: Page<Agent> = new Page<Agent>([], 0, 1, 15, 0, []);
  angent3: Page<Agent> = new Page<Agent>([], 0, 1, 15, 0, []);
  loading = false;
  loading3 = false;
  sortList= [
    {
      value: 'ASC',
      label: '升序'
    },
    {
      value: 'DESC',
      label: '降序'
    },
  ]
  sortList2= [
    {
      value: 'integral',
      label: '积分排名'
    },
    {
      value: 'number',
      label: '签到次数排名'
    },
  ]
  memberSelectArr: Array<MemberSpecific2> = [];
  memberSelectArr3: Array<MemberSpecific3> = [];
  // memberSelectArr: Array<Member> = [];

  load(pageIndex: number, pageSize: number) {
    if (!isEmpty(this.form.date) && !isEmpty(String(this.form.date[0]))) {
      // @ts-ignore
      this.form.createBegin = this.form.date[0].getTime() || '';
      // @ts-ignore
      this.form.createEnd = this.form.date[1].getTime() + 24 * 60 * 60 * 1000 || '';
    } else {
      this.form.createBegin = '';
      this.form.createEnd = '';
    }
    this.loading = true;
    return getMemberPointRanking({
      pageIndex,
      pageSize,
      // nickname: this.form.nickname,
      // phone: this.form.phone,
      // createBegin: this.form.createBegin,
      // createEnd: this.form.createEnd,
    }).then((res) => {
      this.paged = res.data;
    }).finally(() => {
      this.loading = false;
    });
  }
  load3(pageIndex: number, pageSize: number) {
    if (!isEmpty(this.form3.date) && !isEmpty(String(this.form3.date[0]))) {
      // @ts-ignore
      this.form3.createBegin = this.form3.date[0].getTime() || '';
      // @ts-ignore
      this.form3.createEnd = this.form3.date[1].getTime() + 24 * 60 * 60 * 1000 || '';
    } else {
      this.form3.createBegin = '';
      this.form3.createEnd = '';
    }
    this.loading3 = true;
    return getMemberRanking({
      pageIndex,
      pageSize,
      sortDirection: this.form3.sortDirection,
      sortProperties: this.form3.sortProperties,
      // createBegin: this.form.createBegin,
      // createEnd: this.form.createEnd,
    }).then((res) => {
      this.paged3 = res.data;
    }).finally(() => {
      this.loading3 = false;
    });
  }

  reset() {
    this.form.date = [];
    this.form.createBegin = '';
    this.form.createEnd = '';
    this.form.phone = '';
    this.paged.pageIndex = 1;
    this.paged.pageSize = 15;
    this.form.companyId = [];
    this.form.nickname = '';
    this.form.sortProperties = 'id';
    this.form.sortDirection = 'DESC';
    this.form.modelName = '';
    this.form.province = '',
    this.form.city = '',
    this.form.birthdayDate=undefined,
    this.load(this.paged.pageIndex, this.paged.pageSize);
  }
  reset3() {
    this.form3.date = [];
    this.form3.createBegin = '';
    this.form3.createEnd = '';
    this.form3.phone = '';
    this.paged3.pageIndex = 1;
    this.paged3.pageSize = 15;
    this.form3.companyId = [];
    this.form3.nickname = '';
    this.form3.sortProperties = 'integral';
    this.form3.sortDirection = 'DESC';
    this.form3.modelName = '';
    this.form3.province = '',
    this.form3.city = '',
    this.form3.birthdayDate=undefined,
    this.load3(this.paged3.pageIndex, this.paged3.pageSize);
  }

}
